﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Tour.BLL;
using Tour.DAL;


public partial class Admin_Modules_Config_Config : System.Web.UI.Page
{
    public int? ConfigId { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        GetPropertyFromQueryString();
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    void GetPropertyFromQueryString()
    {
        ConfigId = CommonHelper.QueryStringInt("TourId", null);
    }   
    void LoadData()
    {
        grv.DataSource = TblConfigManager.CreateInstant().SelectConfigBy(null,"Id", "DESC","");
        grv.DataBind();
    }
    protected void grv_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        var hdfID = (HiddenField)grv.Rows[e.RowIndex].FindControl("hdfID");
        //var hdfParentId = (HiddenField)grv.Rows[e.RowIndex].FindControl("hdfParentID");
        try
        {
          //  UpdateOrderOffAndDelete(hdfID.Value, 100);
            TblConfigManager.CreateInstant().Delete(hdfID.Value.ToInt());
            Response.Redirect(Request.RawUrl);
            Trace.Warn("Delete Success" + hdfID.Value);
        }
        catch (Exception ex)
        {
            //throw ex;
            Trace.Warn("Delete Error" + hdfID.Value + ex.Message);
        }
        LoadData();
        Response.Redirect(Request.RawUrl);
    }
    //protected void btnUpdateOrder_Click(object sender, EventArgs e)
    //{
    //    for (int i = 0; i < grv.Rows.Count; i++)
    //    {
    //        var txtOrder = (TextBox)grv.Rows[i].FindControl("txtOrder");
    //        //var hdfOrder = (HiddenField)grv.Rows[i].FindControl("hdfOrder");
    //        var hdfConfigId = (HiddenField)grv.Rows[i].FindControl("hdfConfigId");
    //        var hdfID = (HiddenField)grv.Rows[i].FindControl("hdfID");
    //        //int OldIndex = int.Parse(hdfOrder.Value);
    //        int NewIndex = int.Parse(txtOrder.Text);
    //        if (OldIndex != NewIndex)
    //            UpdateOrderOffAndDelete(hdfID.Value, NewIndex);
    //    }
    //    Response.Redirect(Request.RawUrl);
    //}
    //private void UpdateOrderOffAndDelete(string strId, int NewIndex)
    //{
    //    string Whereclause = " And ConfigId IS NULL ";
    //    //if (!strParentId.Equals(""))
    //    //{
    //    //    Whereclause = String.Format(" And ConfigId={0}", strParentId);
    //    //}
    //    string Whereclause1 = String.Format(" Id={0}", strId);
    //    string Whereclause2 = String.Format(" And Id<>{0}", strId);
    //    Tools.SqlHelper.UpdateOrders("TblConfig", Whereclause, Whereclause1, Whereclause2, NewIndex);
    //}
    protected void grv_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {//
        //GetPropertyFromForm();
        grv.PageIndex = e.NewPageIndex;
        LoadData();
    }
}